package com.wxyzz.satserver.likeenshrine.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxyzz.common.core.common.PageParam;
import com.wxyzz.common.core.common.R;
import com.wxyzz.satserver.likeenshrine.param.LikeEnshrineParam;
import com.wxyzz.satserver.likeenshrine.service.LikeEnshrineService;
import com.wxyzz.satserver.likeenshrine.vo.LikeEnshrineVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/likeAndEnshrine")
@Api(tags ="点赞api")
@CrossOrigin
public class LikeEnshrineController {

    @Resource
    private LikeEnshrineService likeEnshrineService;

    /**
     *  点赞 取消点赞
     * @param param
     * @return
     */
    @PostMapping("/addLike")
    @ApiOperation(value = "点赞和取消点赞")
    private R likeInfo (@RequestBody LikeEnshrineParam param) {
        likeEnshrineService.saveLikeInfo(param);
        return R.ok();
    }

    /**
     *  收藏 取消收藏
     * @param param
     * @return
     */
    @PostMapping("/addEnshrine")
    @ApiOperation(value = "收藏和取消收藏")
    private R enshrineInfo (@RequestBody LikeEnshrineParam param) {
        likeEnshrineService.saveEnshrineInfo(param);
        return R.ok();
    }

    /**
     *  点赞收藏具体信息
     * @param param
     * @return
     */
    @GetMapping("/getLikeEnshrineInfo")
    @ApiOperation(value = "当前用户获得的所有的点赞和收藏的详细信息")
    public R getInfo (PageParam param) {
        Page<LikeEnshrineVO> likeAndEnshrineInfo = likeEnshrineService.getLikeAndEnshrineInfo(param);
        return R.ok(likeAndEnshrineInfo);
    }

    /**
     * 获取当前用户所有文章的点赞数和收藏数
     * @return
     */
    @GetMapping("/getCount")
    @ApiOperation(value = "查询当前用户发表的所有文章的点赞数和收藏数")
    public R getLikeAndEnshrineCount() {
        int likeAndEnshrineCount = likeEnshrineService.getLikeAndEnshrineCount();
        return R.ok(likeAndEnshrineCount);
    }
}
